using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintChapterNotes
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintChapterNotes(clsProject cProject)
		{
			//Discarded unreachable code: IL_020e, IL_0225, IL_0230, IL_0240, IL_02f6, IL_02f8, IL_030c, IL_032e
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int step = 2;
				step = 3;
				if (cProject.ChapterCount != 0)
				{
					step = 5;
					clsCollection<int> clsCollection = new clsCollection<int>();
					step = 6;
					frmPickChapters frmPickChapters = new frmPickChapters(ref cProject);
					step = 7;
					frmPickChapters.ShowDialog();
					step = 8;
					if (!frmPickChapters.Cancelled)
					{
						step = 9;
						clsCollection = frmPickChapters.PickedIDs;
						step = 10;
						clsShared.cSubs.BusyMouse();
						step = 11;
						clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Chapter Notes from " + cProject.Title);
						step = 12;
						clsReport.AddTitle();
						step = 13;
						clsReport.AddBR(2);
						step = 14;
						clsReport.OpenTable("cellpadding=5");
						step = 15;
						clsReport.OpenRow();
						step = 16;
						clsReport.OpenCell();
						step = 17;
						IEnumerator enumerator = clsCollection.GetEnumerator();
						bool flag = default(bool);
						while (enumerator.MoveNext())
						{
							int iD = Conversions.ToInteger(enumerator.Current);
							step = 18;
							clsChapter clsChapter = cProject.Chapters.ChapterByID(iD);
							step = 19;
							string text = clsChapter.DescText.Trim();
							step = 20;
							if (Operators.CompareString(text, "", TextCompare: false) == 0)
							{
								step = 21;
								text = "No description";
							}
							step = 22;
							clsReport.AddText("<B>" + clsChapter.Title.Trim() + "</B>");
							step = 23;
							clsReport.AddBR();
							step = 24;
							clsReport.AddText(text);
							step = 25;
							clsReport.AddBR(2);
							step = 26;
							flag = true;
							step = 27;
						}
						step = 28;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						step = 29;
						clsReport.CloseCell();
						step = 30;
						clsReport.CloseRow();
						step = 31;
						clsReport.CloseTable();
						step = 32;
						clsReport.AddFooter(App.Title);
						step = 33;
						if (flag)
						{
							step = 34;
							clsReport.Show();
							step = 35;
							PrintProgressEvent?.Invoke("Printing Complete");
						}
						else
						{
							step = 37;
							clsShared.cLang.TransMsgBox("There are no chapter notes to print");
						}
						step = 38;
						clsShared.cSubs.NormalMouse();
					}
				}
			}
			catch (Exception obj) when ((num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError(obj);
				/*Error near IL_032c: Could not find block for branch target IL_02f8*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
